home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / comment2.zip / COMMENT.ASM next >
Assembly Source File  |  1986-11-08  |  11KB  |  475 lines

  1.  
  2. PAGE    60,132
  3. TITLE  Dummy device driver to echo CONFIG.SYS comments
  4.  
  5. ;------------------------------------------------------------------------------
  6. ;
  7. ; module name = comment.asm
  8. ;
  9. ; copyright(C) 1984    Skip Gilbrech
  10. ;            90 Lexington Ave. #10-G
  11. ;            New York, NY 10016
  12. ;            212-685-0551
  13. ;
  14. ; This code may be freely used and/or modified for any purpose, as long as
  15. ; appropriate credit is given.
  16. ;
  17. ; date written = 05/19/85
  18. ;
  19. ; change activity =
  20. ;
  21. ;   05/19/85 sg ny r1.0:    original date
  22. ;
  23. ; function = Echoes arguments passed on invoking CONFIG.SYS line
  24. ;        (doesn't stay resident)
  25. ;
  26. ; environment =
  27. ;   system = ibm pc (developed under pcdos 3.0 - requires 2.0 or above)
  28. ;
  29. ; processor = microsoft MASM (V3.0) macro assembler
  30. ;
  31. ;------------------------------------------------------------------------------
  32.  
  33. .lfcond
  34.  
  35. FALSE    equ    0
  36. TRUE    equ    not FALSE
  37.  
  38. CR        equ    0dh    ; carriage return
  39. LF        equ    0ah    ; line feed
  40.  
  41. ; dos delimiters:
  42.  
  43. SPACE        equ    ' '    ; space, blank
  44. COMMA        equ    ','    ;
  45. SEMICOLON    equ    ';'    ;
  46. EQUAL_SIGN    equ    '='    ;
  47. TAB        equ    9    ; tab
  48.  
  49. ; dos equates:
  50.  
  51. DOSINT        equ    21h    ; interrupt number for dos functions
  52. DISPLAY_OUT    equ    2    ; display output
  53.  
  54. ;------------------------------------------------------------------------------
  55. ;
  56. ;    EQUATES SPECIFIC TO DEVICE DRIVER
  57. ;
  58. ;------------------------------------------------------------------------------
  59.  
  60. ; definitions for device header attribute bits:
  61. ATTR_CHAR    equ    1000000000000000b    ; bit 15
  62. ATTR_BLOCK    equ    0            ;
  63. ATTR_IOCTL    equ    0100000000000000b    ; bit 14
  64. ATTR_NON_IBM    equ    0010000000000000b    ; bit 13
  65. ATTR_OP_CL_RM    equ    0000100000000000b    ; bit 11
  66. ATTR_CLOCK    equ    0000000000001000b    ; bit 3
  67. ATTR_NUL    equ    0000000000000100b    ; bit 2
  68. ATTR_STDOUT    equ    0000000000000010b    ; bit 1
  69. ATTR_STDIN    equ    0000000000000001b    ; bit 0
  70.  
  71. ; definitions for device driver command codes:
  72.  
  73. DRIVER_INIT        equ    0
  74. MEDIA_CHECK        equ    1
  75. BUILD_BPB        equ    2
  76. IOCTL_INPUT        equ    3
  77. INPUT            equ    4
  78. INPUT_NO_WAIT        equ    5
  79. INPUT_STATUS        equ    6
  80. INPUT_FLUSH        equ    7
  81. OUTPUT            equ    8
  82. OUTPUT_WITH_VERIFY    equ    9
  83. OUTPUT_STATUS        equ    10
  84. OUTPUT_FLUSH        equ    11
  85. IOCTL_OUTPUT        equ    12
  86. DEVICE_OPEN        equ    13
  87. DEVICE_CLOSE        equ    14
  88. REMOVABLE_MEDIA        equ    15
  89.  
  90. ; definitions for request header status error codes (bits 7-0):
  91.  
  92. WRITE_PROTECT        equ    0
  93. UNKNOWN_UNIT        equ    1
  94. DEVICE_NOT_READY    equ    2
  95. UNKNOWN_COMMAND        equ    3
  96. CRC_ERROR        equ    4
  97. BAD_DRQ_STRUC_LENGTH    equ    5
  98. SEEK_ERROR        equ    6
  99. UNKNOWN_MEDIA        equ    7
  100. SECTOR_NOT_FOUND    equ    8
  101. PRINTER_OUT_OF_PAPER    equ    9
  102. WRITE_FAULT        equ    10
  103. READ_FAULT        equ    11
  104. GENERAL_FAILURE        equ    12
  105. INVALID_DISK_CHANGE    equ    15
  106.  
  107. ; definitions for other request header status bits:
  108.  
  109. ERROR_BIT        equ    1000000000000000b    ; bit 15
  110. BUSY_BIT        equ    0000001000000000b    ; bit 9
  111. DONE_BIT        equ    0000000100000000b    ; bit 8
  112.  
  113. ;------------------------------------------------------------------------------
  114.  
  115. SUBTTL    Data Structures
  116. PAGE
  117.  
  118. ;------------------------------------------------------------------------------
  119.  
  120. ; dos 2.0+ device header structure:
  121.  
  122. DEVICE_HDR struc
  123.     DEV_NXT_HDR_OFST    dw    ?
  124.     DEV_NXT_HDR_SEG    dw    ?
  125.     DEV_ATTR        dw    ?
  126.     DEV_STRAT_OFST    dw    ?
  127.     DEV_INT_OFST    dw    ?
  128.     DEV_NAME_UNIT    db    8 dup (0)
  129. DEVICE_HDR ends
  130.  
  131. ; dos 2.0+ request header structure:
  132.  
  133. REQUEST_HDR    struc
  134.     RQ_LEN        db    ?
  135.     RQ_UNIT_CODE    db    ?
  136.     RQ_CMD_CODE        db    ?
  137.     RQ_STATUS        dw    ?
  138.     RQ_DOS_RSVD        db    8 dup (?)
  139.     RQD            db    ?    ; beginning of variable data area
  140. REQUEST_HDR    ends
  141.  
  142. ; extensions to request header for various operations (all start at RQD):
  143.  
  144. RQ_INIT    struc
  145.     RQIN_NUM_UNITS    db    ?
  146.     RQIN_END_ADR    dd    ?
  147.     RQIN_BPB        dd    ?
  148.     RQIN_DRV_NUM    db    ?
  149. RQ_INIT    ends
  150.  
  151. RQ_IO    struc
  152.     RQIO_MED_DESC    db    ?
  153.     RQIO_BUF_ADR    dd    ?
  154.     RQIO_COUNT        dw    ?
  155.     RQIO_START_SEC    dw    ?
  156.     RQIO_VOL_ID        dd    ?
  157. RQ_IO    ends
  158.  
  159. ;------------------------------------------------------------------------------
  160.  
  161. SUBTTL    Data Area
  162. PAGE
  163.  
  164. ;------------------------------------------------------------------------------
  165.  
  166. CODE    segment
  167.     assume    cs:CODE,ds:CODE
  168.  
  169. ;------------------------------------------------------------------------------
  170.  
  171. ATTR    equ ATTR_BLOCK
  172.  
  173. ; device header (Address 0000H in device driver)
  174.  
  175. COMMENT_HDR DEVICE_HDR <-1,-1,ATTR,STRAT_ROUT,INT_ROUT,>
  176.  
  177. even
  178.  
  179. SAVE_SP    dw    ?            ; for old stack
  180. SAVE_SS    dw    ?
  181.  
  182. STRAT_PTR    dd    ?    ; ptr to passed request header
  183.  
  184. ;------------------------------------------------------------------------------
  185.  
  186. SUBTTL    Main Code Area
  187. PAGE
  188.  
  189. ;------------------------------------------------------------------------------
  190. ; save pointer to request header
  191.  
  192. STRAT_ROUT    proc far
  193.  
  194.     mov    word ptr cs:STRAT_PTR,bx        ; store offset
  195.     mov    word ptr cs:STRAT_PTR + 2,es        ; and segment
  196.     ret
  197.  
  198. STRAT_ROUT    endp
  199.  
  200. ;------------------------------------------------------------------------------
  201.  
  202. INT_ROUT    proc far
  203.  
  204.     pushf
  205.     push    ax            ;
  206.  
  207.     mov    cs:SAVE_SS,ss        ; save incoming stack
  208.     mov    cs:SAVE_SP,sp        ;
  209.  
  210.     mov    ax,cs            ; get code seg in AX
  211.  
  212.     cli                ; set up local stack
  213.     mov    ss,ax            ;
  214.     mov    sp,offset STACK_TOP    ;
  215.     sti                ;
  216.  
  217.     push    bx            ;
  218.     push    cx            ;
  219.     push    dx            ;
  220.     push    si            ;
  221.     push    di            ;
  222.     push    bp            ;
  223.     push    es            ;
  224.     push    ds            ;
  225.  
  226.     mov    ds,ax            ; set DS = CS
  227.     les    si,STRAT_PTR        ; point ES:SI to request header
  228.  
  229.                     ; don't bother to check command code
  230.  
  231.     push    es            ; save req. hdr ptr
  232.     push    si            ;
  233.  
  234.     call    ECHO_COMMENTS        ; process & echo comments
  235.  
  236.     pop    si            ; restore req. hdr. ptr.
  237.     pop    es            ;
  238.  
  239.     ; don't allow dos to install driver..
  240.  
  241.     sub    ax,ax            ;
  242.     mov    byte ptr es:[si].(RQD+RQIN_NUM_UNITS),al ; show 0 units
  243.     mov    word ptr es:[si].(RQD+RQIN_END_ADR),ax    ; set adr to beg. of code
  244.     mov    word ptr es:[si].(RQD+RQIN_END_ADR+2),cs ;
  245.     mov    word ptr es:[si].(RQD+RQIN_BPB),ax    ; return null ptr to BPB
  246.     mov    word ptr es:[si].(RQD+RQIN_BPB+2),ax    ;
  247.     mov    es:[si].RQ_STATUS,(ERROR_BIT or DONE_BIT or DEVICE_NOT_READY)
  248.  
  249.     pop    ds            ;
  250.     pop    es            ;
  251.     pop    bp            ;
  252.     pop    di            ;
  253.     pop    si            ;
  254.     pop    dx            ;
  255.     pop    cx            ;
  256.     pop    bx            ;
  257.  
  258.     cli                ; restore old stack
  259.     mov    ss,word ptr cs:SAVE_SS    ;
  260.     mov    sp,word ptr cs:SAVE_SP    ;
  261.     sti                ;
  262.  
  263.     pop    ax
  264.     popf
  265.     ret
  266.  
  267. INT_ROUT    endp
  268.  
  269. ;------------------------------------------------------------------------------
  270.  
  271. ECHO_COMMENTS    proc near
  272.  
  273.     ; copy parms from CONFIG.SYS command line to local buffer
  274.  
  275.     push    ds            ; save data seg
  276.  
  277.     lds    si,es:[si].(RQD+RQIN_BPB) ; pt to passed parms
  278.     mov    es,ax            ; set ES = CS
  279.  
  280.     mov    di,offset PARM_BUF    ; pt to local buf
  281.     mov    cx,PARM_BUF_SIZE    ;
  282.     push    di            ; save offset
  283.     push    cx            ; and num. bytes
  284.     cld                ; auto increment
  285. rep    movsb                ; get the buf
  286.     pop    cx            ; restore num. bytes
  287.     pop    si            ; get buffer offset in SI
  288.     mov    di,si            ; save offset in DI
  289.  
  290.     pop    ds            ; restore data seg
  291. ECHO_C_0:
  292.     lodsb                ; look for CR or LF - there's no NULL,
  293.                     ;  contrary to documentation
  294.     or    al,al            ; NULL can follow filename in 2.0 or 2.1
  295.     jnz    ECHO_C_1        ; not 0, check for cr/lf
  296.     mov    byte ptr [si-1],' '    ; change the NULL to a space
  297.                     ; (and fall through with 0 in AL)
  298. ECHO_C_1:
  299.     cmp    al,CR            ;
  300.     je    ECHO_C_2        ;
  301.     cmp    al,LF            ;
  302.     loopne    ECHO_C_0        ; no match, loop back for count in CX
  303.  
  304. ECHO_C_2:
  305.     mov    byte ptr [si-1],0    ; end buffer with null
  306.     mov    si,di            ; point to beginning of comment string
  307.  
  308.     ; bump SI past the filename
  309.  
  310.     call    SKIP_WHITE        ; returns SI pointing to 1st non-white char
  311.     call    SKIP_NON_WHITE        ; returns SI pointing to 1st white char
  312.     call    SKIP_WHITE        ; returns SI pointing to 1st non-white char
  313.  
  314.     call    CK_LOWER        ; check for lower-case escapes
  315.     call    MSG            ; print null terminated buffer
  316.     ret
  317.  
  318. ECHO_COMMENTS    endp
  319.  
  320. ;------------------------------------------------------------------------------
  321. ; returns SI pointing to 1st non-white char
  322.  
  323. SKIP_WHITE    proc near
  324.  
  325.     mov    al,[si]        ; get byte
  326.     cmp    al,SPACE    ; space?
  327.     je    SKIP_WHITE_1    ; yes, try again
  328.     cmp    al,TAB        ; tab?
  329.     jne    SKIP_WHITE_EXIT    ; no, then it's non-white
  330. SKIP_WHITE_1:
  331.     inc    si        ; bump ptr
  332.     jmp    SKIP_WHITE    ; and check next char.
  333.  
  334. SKIP_WHITE_EXIT:
  335.     ret
  336.  
  337. SKIP_WHITE    endp
  338.  
  339. ;------------------------------------------------------------------------------
  340. ; returns SI pointing to 1st white char
  341.  
  342. SKIP_NON_WHITE    proc near
  343.  
  344.     mov    al,[si]            ; get byte
  345.     or    al,al            ; don't bump pas